package cn.sumpu.app.wlcity.dao.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.sumpu.app.wlcity.dao.CodeDao;
import cn.sumpu.app.wlcity.domain.Code;
import cn.sumpu.app.wlcity.exception.AppBusinessException;

public class CodeDaoImpl extends SqlMapClientDaoSupport implements
		CodeDao {

	private static Logger logger = LoggerFactory
			.getLogger(CodeDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<Code> getCodeList(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (List<Code>) getSqlMapClientTemplate().queryForList(
					"code.getCodeList",map);
		} catch (DataAccessException e) {
			if (logger.isErrorEnabled()) {
				logger.error("Read database failure.", e);
			}
			throw new AppBusinessException("Read database failure.", e);
		}
	}

	@Override
	public void updateCode(Code code) throws AppBusinessException {
		try {
			getSqlMapClientTemplate().update(
					"code.updateCode",code);
		} catch (DataAccessException e) {
			if (logger.isErrorEnabled()) {
				logger.error("update database failure.", e);
			}
			throw new AppBusinessException("update database failure.", e);
		}
	}

	
}
